package com.hspedu.encap;

public class Account {
//    为了封装，将三个属性设置为private
    private String name;
    private double balance;
    private String pwd;

    public Account() {

    }

    public Account(String name, double balance, String pwd) {
        this.setName(name);
        this.setBalance(balance);
        this.setPwd(pwd);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length()>= 2 && name.length() <= 4){
            this.name = name;
        }else{
            System.out.println("名字要求，默认；无名");
            this.name= "null";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance >= 20){
            this.balance = balance;
        }else{
            System.out.println("默认为零");
            this.balance = 0;
        }

    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        if(pwd.length() == 6){this.pwd = pwd;
    }else{
            System.out.println("默认密码为‘000000’");
            this.pwd = "000000";
}}
   public void showInfo(){
       System.out.println("账号信息："+ name+",密码："+pwd+",用户金额:"+balance);
   }
}
